package cn.stylefeng.guns.sys.modular.system.controller;

import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.sys.modular.system.entity.BtyDingdingMonthAttend;
import cn.stylefeng.guns.sys.modular.system.model.params.BtyDingdingDayAttendParam;
import cn.stylefeng.guns.sys.modular.system.model.params.BtyDingdingDayDeptParam;
import cn.stylefeng.guns.sys.modular.system.model.params.BtyDingdingDayEmpParam;
import cn.stylefeng.guns.sys.modular.system.model.params.BtyDingdingMonthAttendParam;
import cn.stylefeng.guns.sys.modular.system.model.result.BtyDingdingMonthAttendResult;
import cn.stylefeng.guns.sys.modular.system.service.BtyDingdingDayAttendService;
import cn.stylefeng.guns.sys.modular.system.service.BtyDingdingDayDeptService;
import cn.stylefeng.guns.sys.modular.system.service.BtyDingdingDayEmpService;
import cn.stylefeng.guns.sys.modular.system.service.BtyDingdingMonthAttendService;
import cn.stylefeng.roses.core.base.controller.BaseController;
import cn.stylefeng.roses.core.reqres.response.ResponseData;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;


/**
 * 半天妖-钉钉-月度-考勤查询控制器
 *
 * @author wjk
 * @Date 2022-05-30 17:16:47
 */
@Controller
@RequestMapping("/btyDingdingMonthAttend")
public class BtyDingdingMonthAttendController extends BaseController {



    private static Logger logger = LoggerFactory.getLogger(BtyDingdingMonthAttendController.class);

    private String PREFIX = "/modular/system/btyDingdingMonthAttend";


    // 获取部门数据
    @Autowired
    private BtyDingdingDayDeptService btyDingdingDayDeptService;

    // 获取员工数据
    @Autowired
    private BtyDingdingDayEmpService btyDingdingDayEmpService;

    // 获取员工，月份每天的考勤数据
    @Autowired
    private BtyDingdingDayAttendService btyDingdingDayAttendService;

    // 获取员工月份的考勤数据
    @Autowired
    private BtyDingdingMonthAttendService btyDingdingMonthAttendService;

    /**
     * 跳转到主页面
     *
     * @author wjk
     * @Date 2022-05-30
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "/btyDingdingMonthAttend.html";
    }

    /**
     * 跳转到详情界面
     * @param id
     * @param date
     * @param model
     * @return
     */
    @RequestMapping(value = "/detail_view/{id}/{date}")
    public String detail_view(@PathVariable String id, @PathVariable String date, Model model) {
        model.addAttribute("empId", id);
        model.addAttribute("attendYearMonth", date);
        return PREFIX + "/detail_view.html";
    }

    /**
     * 新增页面
     *
     * @author wjk
     * @Date 2022-05-30
     */
    @RequestMapping("/add")
    public String add() {
        return PREFIX + "/btyDingdingMonthAttend_add.html";
    }

    /**
     * 编辑页面
     *
     * @author wjk
     * @Date 2022-05-30
     */
    @RequestMapping("/edit")
    public String edit() {
        return PREFIX + "/btyDingdingMonthAttend_edit.html";
    }

    /**
     * 新增接口
     *
     * @author wjk
     * @Date 2022-05-30
     */
    @RequestMapping("/addItem")
    @ResponseBody
    public ResponseData addItem(BtyDingdingMonthAttendParam btyDingdingMonthAttendParam) {
        this.btyDingdingMonthAttendService.add(btyDingdingMonthAttendParam);
        return ResponseData.success();
    }

    /**
     * 编辑接口
     *
     * @author wjk
     * @Date 2022-05-30
     */
    @RequestMapping("/editItem")
    @ResponseBody
    public ResponseData editItem(BtyDingdingMonthAttendParam btyDingdingMonthAttendParam) {
        this.btyDingdingMonthAttendService.update(btyDingdingMonthAttendParam);
        return ResponseData.success();
    }

    /**
     * 删除接口
     *
     * @author wjk
     * @Date 2022-05-30
     */
    @RequestMapping("/delete")
    @ResponseBody
    public ResponseData delete(BtyDingdingMonthAttendParam btyDingdingMonthAttendParam) {
        this.btyDingdingMonthAttendService.delete(btyDingdingMonthAttendParam);
        return ResponseData.success();
    }

    /**
     * 查看详情接口
     *
     * @author wjk
     * @Date 2022-05-30
     */
    @RequestMapping("/detail")
    @ResponseBody
    public ResponseData detail(BtyDingdingMonthAttendParam btyDingdingMonthAttendParam) {
        BtyDingdingMonthAttend detail = this.btyDingdingMonthAttendService.getById(btyDingdingMonthAttendParam.getId());
        return ResponseData.success(detail);
    }

    /**
     * 查询列表
     *
     * @author wjk
     * @Date 2022-05-30
     */
    @ResponseBody
    @RequestMapping("/list")
    public LayuiPageInfo list(BtyDingdingMonthAttendParam btyDingdingMonthAttendParam) {
        return this.btyDingdingMonthAttendService.findPageBySpec(btyDingdingMonthAttendParam);
    }


    /**
     * 开始同步半天妖部门的员工的每天数据到月度数据
     * 月度数据
     * @author
     * @Date 2022-06-02
     */
    @RequestMapping("/addBtyDingdingMonthAttend")
    @ResponseBody
    public ResponseData addBtyDingdingMonthAttend(@RequestBody BtyDingdingMonthAttendParam btyDingdingMonthAttendParam) {
        Map<String,String> map = this.btyDingdingMonthAttendService.addBtyDingdingMonthAttend(btyDingdingMonthAttendParam);
        return ResponseData.success(map);
    }



    /**
     * 同步月度数据到liu1_qin
     * 月度数据
     * @author
     * @Date 2022-06-08
     */
    @RequestMapping("/synchronousliuQin")
    @ResponseBody
    public ResponseData synchronousliuQin() {
        Map<String,String> map = this.btyDingdingMonthAttendService.synchronousliuQin();
        return ResponseData.success(map);
    }

    /**
     * 定时任务调取同步半天妖钉钉考勤的数据
     * @author
     * @Date 2022-06-08
     */
    @RequestMapping("/taskSynchronousAttend")
    @ResponseBody
    public ResponseData taskSynchronousAttend(@RequestBody BtyDingdingMonthAttendParam btyDingdingMonthAttendParam) throws InterruptedException {


        long t1=System.currentTimeMillis();
        BtyDingdingDayDeptParam btyDingdingDayDeptParam = new BtyDingdingDayDeptParam();
        btyDingdingDayDeptParam.setAttendYearMonth(btyDingdingMonthAttendParam.getAttendYearMonth());
        Map<String,String> map1 = this.btyDingdingDayDeptService.addBtyDingdingMonthDept(btyDingdingDayDeptParam);

        BtyDingdingDayEmpParam btyDingdingDayEmpParam = new BtyDingdingDayEmpParam();
        btyDingdingDayEmpParam.setAttendYearMonth(btyDingdingMonthAttendParam.getAttendYearMonth());
        Map<String,String> map2 = this.btyDingdingDayEmpService.addBtyDingdingMonthEmp(btyDingdingDayEmpParam);

        BtyDingdingDayAttendParam btyDingdingDayAttendParam = new BtyDingdingDayAttendParam();
        btyDingdingDayAttendParam.setAttendYearMonth(btyDingdingMonthAttendParam.getAttendYearMonth());
        Map<String,String> map3 = this.btyDingdingDayAttendService.addBtyDingdingDayAttend(btyDingdingDayAttendParam);

        Map<String,String> map4 = this.btyDingdingMonthAttendService.addBtyDingdingMonthAttend(btyDingdingMonthAttendParam);


        //Map<String,String> map5 = this.btyDingdingMonthAttendService.synchronousliuQin();

        long t2=System.currentTimeMillis();
        long t=(t2-t1)/1000;
        logger.info("******************************************************************************************************");
        logger.info("******************************************************************************************************");
        logger.info("******************************************************************************************************");
        logger.info("用时:{}",t);
        logger.info("******************************************************************************************************");
        logger.info("******************************************************************************************************");
        logger.info("******************************************************************************************************");
        return ResponseData.success(map4);
    }

    /**
     * 导出excel
     *
     */
    @ResponseBody
    @RequestMapping("/export")
    public List<BtyDingdingMonthAttendResult> export(BtyDingdingMonthAttendParam btyDingdingMonthAttendParam) {
        return this.btyDingdingMonthAttendService.export(btyDingdingMonthAttendParam);
    }

    /**
     * 漏打卡详情
     *
     */
    @ResponseBody
    @RequestMapping("/detailList")
    public ResponseData detailList(BtyDingdingMonthAttendParam btyDingdingMonthAttendParam) {
        return this.btyDingdingMonthAttendService.detailList(btyDingdingMonthAttendParam);
    }

}


